<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>贵阳轨道交通</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <META http-equiv=Content-Type content="text/html; charset=utf-8">
    <META content="MSHTML 6.00.3790.4807" name=GENERATOR>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no, viewport-fit=cover">
<meta http-equiv="x-dns-prefetch-control" content="on">
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=ad17babae123cfc6568dd60e371ed512&plugin=AMap.Transfer"></script>
    <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
    
    <style>
      html,
      body,
      #container {
          width: 100%;
          height: 100%;
      }
      #panel {
          position: fixed;
          background-color: white;
          max-height: 90%;
          overflow-y: auto;
          top: 10px;
          right: 10px;
          width: 280px;
      }
      #panel .amap-call {
          background-color: #009cf9;
          border-top-left-radius: 4px;
          border-top-right-radius: 4px;
      }
      #panel .amap-lib-transfer {
        border-bottom-left-radius: 4px;
          border-bottom-right-radius: 4px;
          overflow: hidden;
      }
    </style>

</head>
<body>
 
<div id="container"  >
</div>  
<div id="panel"></div>

<script>
     /*var map = new AMap.Map("container", {
        center: [116.358786,39.935783],
        zoom: 14
    });*/

 var map = new AMap.Map("container", {
                resizeEnable: true,
                center: [106.675334,26.619512],
                zoom: 12
            });

    var transferOption = {
        // map: map,
        nightflag: true, // 是否计算夜班车
        city: '贵阳市',
      /*  panel: 'panel',*/
        outlineColor: '#ffeeee',
        autoFitView: true,
        policy: AMap.TransferPolicy.LEAST_TIME // 其它policy取值请参照 https://lbs.amap.com/api/javascript-api/reference/route-search#m_TransferPolicy
    }

    var transfer = new AMap.Transfer(transferOption)

    //根据起、终点坐标查询公交换乘路线
    // 地铁1号线：贵阳市窦官站->小孟工业园站 new AMap.LngLat(106.569271,26.653414), new AMap.LngLat(106.709631,26.497717)
    // 地铁2号线：
    transfer.search(new AMap.LngLat(113.416979,31.721066), new AMap.LngLat(106.784708,27.449092), function(status, result) {
        // result即是对应的公交路线数据信息，相关数据结构文档请参考  https://lbs.amap.com/api/javascript-api/reference/route-search#m_TransferResult
        var subwayPathData = [];

        if (status === 'complete') {
            var path = result.plans[0].path;
            var on_station =  result.plans[0].segments[0].transit.on_station;
             var off_station =  result.plans[0].segments[0].transit.off_station;
            var stops = result.plans[0].segments[0].transit.via_stops;
            stops.unshift(on_station);
            stops.push(off_station);

                console.info('22公交路线数据查询成功', result);


             console.info('22公交路线数据查询成功 path',JSON.stringify(path));

              console.info('22公交路线数据查询成功 stops', JSON.stringify(stops));

             var marker, lineArr = JSON.parse(JSON.stringify(path));

               
                marker = new AMap.Marker({
                    map: map,
                    position: [106.569271,26.653414],
                    icon: "https://a.amap.com/jsapi/static/image/plugin/marker/subway-stop-rect.png",
                    offset: new AMap.Pixel(-26, -13),
                    autoRotation: true,
                    angle:-90,
                });

                // 绘制轨迹
                var polyline = new AMap.Polyline({
                    map: map,
                    path: lineArr,
                    showDir:true,
                    strokeColor: "#AF5",  //线颜色
                    // strokeOpacity: 1,     //线透明度
                    strokeWeight: 5,      //线宽
                    // strokeStyle: "solid"  //线样式
                });

                var passedPolyline = new AMap.Polyline({
                    map: map,
                    // path: lineArr,
                    strokeColor: "#AF5",  //线颜色
                    // strokeOpacity: 1,     //线透明度
                    strokeWeight: 6,      //线宽
                    // strokeStyle: "solid"  //线样式
                });


                marker.on('moving', function (e) {
                    passedPolyline.setPath(e.passedPath);
                });


        } else {
            console.info('公交路线数据查询失败' + result)
        }
    });
</script>
</body>
</html>